Skip to content

fix(ts-client): prevent Overview crash from single-resource cache seeding#3055

Merged
jamiepine merged 1 commit into
spacedriveapp:mainfrom
slvnlrt:fix/overview-crash-single-resource-seeding
Apr 19, 2026
Merged

fix(ts-client): prevent Overview crash from single-resource cache seeding#3055
jamiepine merged 1 commit into
spacedriveapp:mainfrom
slvnlrt:fix/overview-crash-single-resource-seeding

Conversation

@slvnlrt
Copy link
Copy Markdown
Contributor

@slvnlrt slvnlrt commented Apr 15, 2026

Re-opened from #3048 (auto-closed when spacedrive-data was merged into main). Rebased onto current main.

Summary

  • updateSingleResource seeded the TanStack cache with { files: [...], total_count, has_more } when oldData was null (buffer replay race). This list-shaped fallback broke single-resource queries like libraries.info where the response is a plain Library object, causing TypeError: Cannot read properties of undefined (reading 'total_capacity') on the Overview page.
  • Returns undefined instead (TanStack no-op) so the queryFn delivers the correct shape. Batch seeding in updateBatchResources is preserved for file listings.

Root Cause

The subscription manager pre-registers the listener before transport.subscribe() (correct for capturing buffer replay). When the daemon has a recent ResourceChanged for library (from recalculate_statistics()), the buffer replay delivers it before the queryFn resolves. With oldData null, the fallback creates { files: [Library] } which has no statistics key, crashing the Overview component.

Why only updateSingleResource

updateBatchResources keeps its { files: [...] } seeding because ResourceChangedBatch events are only emitted by the file indexing pipeline, where the list shape is correct. Single ResourceChanged events affect all resource types (library, device, volume, location, tag), most of which don't use list-shaped responses.

…ding

updateSingleResource seeded the TanStack cache with { files: [...] }
when oldData was null (buffer replay race). This list-shaped fallback
broke single-resource queries like libraries.info where the response
is a plain object, causing TypeError on statistics.total_capacity.

Return undefined instead so the queryFn delivers the correct shape.
Batch seeding in updateBatchResources is preserved for file listings.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9774be20-1ddb-4168-aa85-6160493fce62

📥 Commits

Reviewing files that changed from the base of the PR and between d313d5a and ca0c13d.

📒 Files selected for processing (1)
  • packages/ts-client/src/hooks/useNormalizedQuery.ts

Walkthrough

The cache seeding behavior in updateSingleResource was modified to return undefined instead of inserting a fallback list-shaped object when oldData is missing. This ensures the update is not applied until the query's queryFn provides the correct data.

Changes

Cohort / File(s) Summary
Cache Seeding Behavior
packages/ts-client/src/hooks/useNormalizedQuery.ts
Removed fallback cache seeding for single-resource updates; now returns undefined when oldData is missing instead of inserting a list-shaped placeholder, allowing correct data from queryFn to be used.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 The cache now waits with patient care,
No false friends placed in empty air,
For truth will come when time is right,
And data flows pure and bright!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the specific issue (Overview crash from single-resource cache seeding) and the fix approach (prevent), accurately summarizing the main change.
Description check ✅ Passed The description provides comprehensive context including root cause analysis, why the fix was needed, and why only updateSingleResource was modified, though it does not explicitly reference a closed issue as required by the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jamiepine jamiepine merged commit d14413a into spacedriveapp:main Apr 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants